# Copyright (c) 2008-2011, Thomas Handorf
# 
# This file is part of libScopes.
# libScopes is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# libScopes is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public License
# along with libScopes.  If not, see <http://www.gnu.org/licenses/>.
#
package Scopes::Functions;

use base qw(Exporter);

our @EXPORT=qw(initChannels dScopeStep dScope dScopeRun scope findseed fullRand idxSort weightRand getTimeSeries getReactionTimeSeries);

sub initChannels{
   return new Scopes::Channels(shift()->{c_net});
}
sub dScopeStep{
   Scopesc::dScopeStep(shift()->{c_net},@_);
}
sub dScope{
   return Scopesc::dScope(shift()->{c_net},@_);
}
sub dScopeRun{
   Scopesc::dScopeRun(shift()->{c_net},@_);
}
sub scope{
   return Scopesc::scope(shift()->{c_net},@_);
}
sub findseed{
   return Scopesc::findseed(shift()->{c_net},@_);
}
*fullRand = *Scopesc::fullRand;
*idxSort = *Scopesc::idxSort;
*weightRand = *Scopesc::weightRand;

sub getTimeSeries{
   my $net=shift;
   my $sl=shift; # StateList
   my $comid=$net->comIDs;
   my $ts={}; # time series
   for (my $i=0;$i<$sl->size;$i++){
      my $cb=$sl->at($i)->combine;
      for (my $n=0;$n<$net->numC;$n++){
         push(@{$ts->{$comid->[$n]}},$cb->at($n));
      }
   }
   return $ts;
}
sub getReactionTimeSeries{
   my $net=shift;
   my $sl=shift; # StateList
   my $reaid=$net->reaIDs;
   my $ts={}; # time series
   for (my $i=0;$i<$sl->size;$i++){
      my $cb=$sl->at($i)->combineReactionState();
      for (my $n=0;$n<$net->numR;$n++){
         push(@{$ts->{$reaid->[$n]}},$cb->at($n));
      }
   }
   return $ts;
}